home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Belgian Amiga Club - ADF Collection
/
BS1 part 43.zip
/
Sources C- WorkDisk V.adf
/
dos
/
mkdirs.c
< prev
next >
Wrap
C/C++ Source or Header
|
1987-02-16
|
3KB
|
122 lines
/*
* =====================================================================
*
* Program : MKDIRS or MakeDirectories. Date : July 18th 1987.
*
* Author : J. Van Houtven.
*
* =====================================================================
*/
#include "libraries/dosextens.h"
# define MAX_NR_OF_SUBDIRS 200
/* Only UnLock() locks that are obtained with Lock() or DupLock() (?) !!!! */
extern struct FileLock *CreateDir(), *CurrentDir();
struct FileLock *next_lock[MAX_NR_OF_SUBDIRS+1],
*current_lock,
*first_lock;
int i, nr_of_subdirs;
main(argc,argv)
int argc;
char *argv[];
{
char *dirname, *drivename;
struct FileLock *create_lock;
void die(), CloseALL();
if(argc>1)
drivename = argv[1];
else
{
puts("Usage : MKDIRS <drive> <nr_of_subdirs> <name of subdirs>.\n");
puts("<drive> : 'df1:', 'df2:' or 'df3:'");
puts("<nr_of_subdirs> : INTEGER NUMBER between [1-200], DEFAULT = 50");
puts("<name of subdirs> : CHARACTER STRING, DEFAULT = \" * BAMIGA SECTOR ONE * \"\n");
exit(0);
}
if(argc>2)
{
nr_of_subdirs = atoi(argv[2]);
if((nr_of_subdirs <1) || (nr_of_subdirs>MAX_NR_OF_SUBDIRS))
{
puts("<nr_of_subdirs> must be within [1-200] !\n");
exit(0);
}
}
else
nr_of_subdirs = 50;
if(argc>3)
dirname = argv[3];
else
dirname = " * BAMIGA SECTOR ONE * ";
/* ====== mkdirs routine ====== */
/* init next_lock[] */
for(i=0;i<=nr_of_subdirs;i++) next_lock[i] = 0;
first_lock = CurrentDir(0);
CurrentDir(first_lock);
if( (current_lock = Lock(drivename,ACCESS_WRITE) ) == 0)
{
die("Couldn't get a lock on specified drive !\n");
}
next_lock[0] = current_lock;
for(i=0;i<nr_of_subdirs;i++)
{
CurrentDir(next_lock[i]);
/* Test if "dirname" already exists ... */
/* BUG : We test this by trying to obtain a lock on "dirname"
but "dirname" could still be a normal file ! */
if((create_lock = Lock(dirname,ACCESS_WRITE)) !=0)
{
UnLock(create_lock);
die("Subdirectory already exists !\n");
}
if((create_lock = CreateDir(dirname)) == 0)
die("Couldn't create subdirectory !\n");;
UnLock(create_lock);
if((next_lock[i+1] = Lock(dirname,ACCESS_WRITE)) == 0)
die("Couldn't obtain a lock on subdirectory\n");
}
CloseALL();
} /* ====== end main ====== */
void CloseALL()
{
for(i=nr_of_subdirs;i>=1;i--) if(next_lock[i]) UnLock(next_lock[i]);
CurrentDir(first_lock);
if(current_lock) UnLock(current_lock);
}
void die(errormsg)
char *errormsg;
{
CloseALL();
puts(errormsg);
exit(0);
}